<?php
class OrganModel extends CommonModel
{
	public function __construct($uid)
	{
		parent::__construct('organ');
	    if(empty($uid) || intval($uid) != $uid){trigger_error("UID ERROR!");exit;}
	    $this->uid = $uid;
	}
	
	protected function _setFields()
	{
		return array(
			'AID',
			'UID',
			'OrganName',
		    'OrganType',
			'Status',
			'Remark'
		);
	}
	
	protected function _setPrimaryKeys()
	{
		return array(
			'AID'
		);
	}
	
	protected function _setAutoIncrementFields()
	{
		return array(
			'AID'
		);
	}
	
	protected function _setForeignKeyRelation()
	{
		return array();
	}
	
	public function add($data)
	{
		$data = $this->_getFieldsData($data);
		$dbMaster = DB::getMaster();
		$sql = "INSERT INTO `{$this->_table}`(`UID`,`OrganName`,`OrganType`,
				`Status`,`Remark`) 
				VALUES('{$this->uid}','{$data['OrganName']}','{$data['OrganType']}',
				'{$data['Status']}','{$data['Remark']}')";
		return $dbMaster->exec($sql);
	}
	
	public function getAll()
	{
		$dbSlave = DB::getSlave();
		$sql = "SELECT * FROM `{$this->_table}` WHERE UID='{$this->uid}'";
		$result = $dbSlave->query($sql);
		return $result;
	}
	
	public function getBank()
	{
	    $dbSlave = DB::getSlave();
		$sql = "SELECT * FROM `{$this->_table}` WHERE UID='{$this->uid}' AND OrganType=1";
		return $dbSlave->query($sql);
	}

	protected function _validationField($fieldName, $value) 
	{
		return true;
	}
	
	public function __destruct()
	{
		//echo 'bank model destruct!';
	}
}